var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
Page({
  data: {
    imgUrl: globalData.imgUrl,
    msg:'',
    info:[],
  },
  save: function () {
    let that = this;
    let params = new Object();
    params.couponNo = wx.getStorageSync("code");
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    let sid = wx.getStorageSync("JSESSIONID");
    console.log("param:" + JSON.stringify(params));
    console.log("header:openId:" + openId + ",sid:" + sid);
    wx.request({
      header: { "openId": openId, "sid": sid },
      url: httpsUrl + "/businessManage/couponVerify",
      dataType: "json",
      method: "POST",
      data: params,
      success: function (res) {
        commonUtil.hideLoading();
        console.log(JSON.stringify(res));
        var res = res.data;
        if (res.result == 0) {
          commonUtil.showSuccessToast("核销成功！");
          //延时执行
          setTimeout(function () {
            wx.navigateBack({
              delta: 1,
            })
          }, 2000) //延迟时间 这里是1000为1秒
        } else {
          commonUtil.showModal(res.msg);
        }
      }
    })
  },
  onLoad: function (options) {
    let that = this;
    let params = new Object();
    params.couponNo = wx.getStorageSync("code");
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    let sid = wx.getStorageSync("JSESSIONID");
    console.log("param:" + JSON.stringify(params));
    console.log("header:openId:" + openId + ",sid:" + sid);
    wx.request({
      header: { "openId": openId, "sid": sid },
      url: httpsUrl + "/businessManage/couponInfo",
      dataType: "json",
      method: "POST",
      data: params,
      success: function (res) {
        commonUtil.hideLoading();
        console.log(JSON.stringify(res));
        var res = res.data;
        if (res.result == 0) {
          that.setData({info:res.data})
        } else {
          that.setData({msg:res.msg})
          // commonUtil.showModal(res.msg);
        }
      }
    })
  },
})